<?php $this->load->view('header');?>

<body class="childrenBody custom_body">
	<div class="custom_main">
		<fieldset class="layui-elem-field layui-field-title">
		  <legend>课程信息</legend>
		</fieldset>

		<form class="layui-form">
			<div class="layui-tab">
			  <ul class="layui-tab-title">
			    <li class="layui-this">通用信息</li>
			    <li>器械工具</li>
			    <li>详情介绍</li>
			  </ul>
			  <div class="layui-tab-content">

			  	<!-- 通用信息 -->
			    <div class="layui-tab-item layui-show">
					<div class="layui-form-item">
						<label class="layui-form-label">封面图：</label>
						<div class="layui-upload">
						  <button type="button" class="layui-btn layui-btn-primary" id="test1">上传</button>
						  <div class="layui-upload-list" style="display: inline;">
						    <img class="layui-upload-img" id="demo1">
						    <p id="demoText" style="display: inline;color: #ccc">建议大小不超过2M。支持格式jpg、jpeg、gif、png</p>
						  </div>
						  <input type="hidden" name="theme_img" value="<?=$theme_img?>" />
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 课程类型：</label>
						<div class="layui-input-block">
							<input type="radio" name="type_id" value="0" title="私教"  checked>
		      				<input type="radio" name="type_id" value="1" title="团教" <?php if ($type_id == 1):?> checked <?php endif;?>>
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 课程名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="name" required lay-verify="required" placeholder="请输入课程名称" autocomplete="off" class="layui-input" value="<?=$name?>">
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 标题：</label>
						<div class="layui-input-inline">
							<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" value="<?=$title?>">
						</div> 
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 所属场馆：</label>
						<div class="layui-input-inline">
							<select name="shop_id" lay-verify="required">
							  <option value="" selected>请选择场馆</option>
							  <?php foreach ($venue as $item):?>
							  <option value="<?=$item['id']?>"<?php if ($shop_id == $item['id']):?> selected <?php endif;?>><?=$item['name']?></option>
							  <?php endforeach;?>
							</select> 
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 教练员：</label>
						<div class="layui-input-inline">
							<select name="cid" lay-verify="required">
							  <option value="" selected>请选择教练</option>
		  					  <?php foreach ($coach_list as $item):?>
							  <option value="<?=$item['id']?>" <?php if ($cid == $item['id']):?> selected <?php endif;?>><?=$item['nickname']?></option>
							  <?php endforeach;?>
							</select> 
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"> 包含动作：</label>
						<div class="layui-input-block">
							<?php foreach ($sport as $item):?>
							<input type="checkbox" name="sport[<?=$item['id']?>]" title="<?=$item['name']?>" lay-skin="primary" lay-verify="checkboxmustbe" id="sport<?=$item['id']?>" value="<?=$item['id']?>" /> 
							<?php endforeach;?>
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"> 课程难度：</label>
						<div class="layui-input-inline">
							<input type="text" name="nandu" placeholder="例如：N1" autocomplete="off" class="layui-input" value="<?=$nandu?>">
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"> 燃脂量：</label>
						<div class="layui-input-inline">
							<input type="text" name="ranzhi" placeholder="只可输入数字" autocomplete="off" class="layui-input" value="<?=$ranzhi?>">
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"><i>*</i> 运动时长：</label>
						<div class="layui-input-inline">
							<input type="text" name="duration" required lay-verify="required" placeholder="只可输入数字" autocomplete="off" class="layui-input" value="<?=$duration?>">
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i" style="width: 84px;"> 可预约人数：</label>
						<div class="layui-input-inline">
							<input type="text" name="max_num" placeholder="只可输入数字" autocomplete="off" class="layui-input" value="<?=$max_num?>">
						</div> 
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label custom_i"> 适用人群：</label>
						<div class="layui-input-block">
							<input type="text" name="suitable" placeholder="例如：腰腹|大腿|手臂" autocomplete="off" class="layui-input" value="<?=$suitable?>">
						</div> 
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">课程简介：</label>
					    <div class="layui-input-block">
					      <textarea name="info" placeholder="请输入简介" class="layui-textarea"><?=$info?></textarea>
					    </div>
					</div>

					<!--div class="layui-form-item">
						<label class="layui-form-label custom_i"> 是否显示：</label>
						<div class="layui-input-block">
							<input type="radio" name="status" value="1" title="显示" checked />
							<input type="radio" name="status" value="0" title="不显示" <?php if ($status == 0):?> checked <?php endif;?> />
						</div>
					</div-->
					
			    </div>
				
				<!-- 器械 -->
			    <div class="layui-tab-item">
					<div class="layui-form-item">
						<label class="layui-form-label custom_i"> 器械名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="apellation" placeholder="请输入名称" autocomplete="off" class="layui-input" value="<?=$apellation?>">
						</div> 
					</div>	

			    	<div class="layui-form-item">
						<label class="layui-form-label">说明：</label>
					    <div class="layui-input-block">
					      <textarea name="desc" placeholder="请输入说明" class="layui-textarea"><?=$desc?></textarea>
					    </div>
					</div>
			    </div>

				<!-- 详情 -->
			    <div class="layui-tab-item">
					<textarea class="layui-textarea" id="LAY_demo1" style="display: none"><?=$content?></textarea>
			    </div>
			  </div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="course_id" value="<?=$courses_id?>">
					<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="addUser">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		layui.config({
			version: true
		}).use(['jquery','layer', 'form', 'laytpl', 'upload', 'element','layedit'],function(){
			var form = layui.form,
				layer = parent.layer === undefined ? layui.layer : parent.layer,
				laypage = layui.laypage,
				laytpl = layui.laytpl,
				upload = layui.upload,
				layedit = layui.layedit,
				element = layui.element,
				$ = layui.jquery;

			var _edit = <?=$edit_sport?>;//动作数据

			var image_upload = '<?=$image_upload_url?>';
				//自定义验证规则  
				// form.verify({ 
				// 	checkboxmustbe: function(){  
				// 		if (!$("#sport").is(":checked")) {
				// 			return "必须选择包含动作";
				// 		}
			 //        }
				// }); 

			//上传图片
			var uploadInst = upload.render({
			    elem: '#test1'
			    ,url: image_upload
			    ,before: function(obj){
			      //预读本地文件示例，不支持ie8
			      obj.preview(function(index, file, result){
			        $('#demo1').attr('src', result); //图片链接（base64）
			        $("#demo1").css("width","100px");
			      });
			    }
			    ,done: function(res){
			      //如果上传失败
			      if(res.result_code > 0){
			        return layer.msg('上传失败');
			      } 
			      //上传成功
			      else{
			      	$("input[name='theme_img']").val(res.data[0].url);
			      }
			     
			    }
			    ,error: function(){
			      //演示失败状态，并实现重传
			      var demoText = $('#demoText');
			      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
			      demoText.find('.demo-reload').on('click', function(){
			        uploadInst.upload();
			      });
			    }
			  });

			//选中已选择的动作
			layui.each(_edit, function(index, el) 
			{
				var child = $('.layui-form').find('input[type="checkbox"][value="'+el+'"]');
				child.each(function(i, item){ 
					item.checked = true;
			    });
			});


			  //构建一个默认的编辑器
			  var index = layedit.build('LAY_demo1',{
			  	tool: ['strong','italic','underline','del','|','left','center','right','link','unlink']
			  });

				//提交表单
				form.on("submit(addUser)",function(data)
				{
					data.field['content'] = layedit.getContent(index); //详情简介

					$.post('admin.php/Courses/insert_courses', data.field, function(result) 
					{
						if (result.status == 200) 
						{
							layer.msg(result.message, {icon: 1});
							location.reload();
						}
						else
						{
							layer.msg(result.message, {icon: 5});
						}

					},"json");

					return false;
				});

				form.render(); //更新全部

		});

	</script>

</body>
</html>